package hust.music.action;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.entity.User;
import hust.music.service.UserModService;
import hust.music.util.DynamicInfo;
import hust.music.util.Page;

/**
 * FollowAction
 * 
 * @author Txazo
 * @since 1.0
 */
@Controller
@Scope("session")
public class FollowFanAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	/** 当前页 */
	private int pageNow;
	/** 每页显示数 */
	private int pageSize = 10;
	/** 分页 */
	private Page page;

	/** 关注的人 */
	private List<DynamicInfo> follow = new ArrayList<DynamicInfo>();
	/** 粉丝 */
	private List<DynamicInfo> fan = new ArrayList<DynamicInfo>();
	/** 好友 */
	private List<DynamicInfo> friend = new ArrayList<DynamicInfo>();

	@Autowired
	private UserModService userModService;

	/**
	 * 获取用户关注的人动态信息
	 * 
	 * @return 逻辑视图
	 */
	public String follow() {
		User user = (User) session.get("follow");

		if (user == null) {
			user = (User) session.get("user");
		}

		int first = (pageNow - 1) * pageSize;
		int length = userModService.getTotalFollow(user);

		follow = userModService.getFollow(user, first, this.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "follow";
	}

	/**
	 * 获取用户关注的人动态信息
	 * 
	 * @return 逻辑视图
	 */
	public String fan() {
		User user = (User) session.get("follow");

		if (user == null) {
			user = (User) session.get("user");
		}

		int first = (pageNow - 1) * pageSize;
		int length = userModService.getTotalFan(user);

		fan = userModService.getFan(user, first, this.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "fan";
	}

	/**
	 * 获取用户关注的人动态信息
	 * 
	 * @return 逻辑视图
	 */
	public String friend() {
		User user = (User) session.get("follow");

		if (user == null) {
			user = (User) session.get("user");
		}

		int first = (pageNow - 1) * pageSize;
		int length = userModService.getTotalFriend(user);

		friend = userModService.getFriend(user, first, this.getPageSize());

		page = new Page(this.getPageNow(), this.getPageSize(), length);

		return "friend";
	}

	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<DynamicInfo> getFollow() {
		return follow;
	}

	public void setFollow(List<DynamicInfo> follow) {
		this.follow = follow;
	}

	public List<DynamicInfo> getFan() {
		return fan;
	}

	public void setFan(List<DynamicInfo> fan) {
		this.fan = fan;
	}

	public List<DynamicInfo> getFriend() {
		return friend;
	}

	public void setFriend(List<DynamicInfo> friend) {
		this.friend = friend;
	}

}
